package com.concurrent.water.machine;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Objects;
import java.util.UUID;

public class BillDO implements Comparable<BillDO> {
    private final String id;
    private final LocalDateTime time;
    private final BigDecimal money;

    public BillDO(String id, LocalDateTime time, BigDecimal money) {
        this.id = id;
        this.time = time;
        this.money = money;
    }

    public static BillDO fromMoney(BigDecimal money) {
        return new BillDO(UUID.randomUUID().toString(), LocalDateTime.now(), money);
    }

    @Override
    public int compareTo(BillDO o) {
        return this.time.compareTo(o.time);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        BillDO billDO = (BillDO) o;
        return Objects.equals(id, billDO.id) && Objects.equals(time, billDO.time) && Objects.equals(money, billDO.money);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, time, money);
    }

    @Override
    public String toString() {
        return "BillDO{" +
                "id='" + id + '\'' +
                ", time=" + time +
                ", money=" + money +
                '}';
    }
}
